home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / +system+ / tools / gui / bgui.lha / bgui / Examples / Source / AddButtons.c next >
C/C++ Source or Header  |  2000-02-27  |  6KB  |  208 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/AddButtons.c,v 1.1.2.3 1999/08/01 03:56:35 mlemos Exp $
  3.  *
  4.  * AddButtons.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1994 Paul Weterings.
  8.  * All Rights Reserved.
  9.  *
  10.  * Modified by Ian J. Einman, 4/26/96
  11.  *
  12.  * $Log: AddButtons.c,v $
  13.  * Revision 1.1.2.3  1999/08/01 03:56:35  mlemos
  14.  * Added missing disposal of removed buttons.
  15.  *
  16.  * Revision 1.1.2.2  1999/07/28 16:40:19  mlemos
  17.  * Fixed the code that attempted to remove a button that failed to be inserted
  18.  * by simply disposing the object.
  19.  *
  20.  * Revision 1.1.2.1  1998/02/28 17:44:45  mlemos
  21.  * Ian sources
  22.  *
  23.  *
  24.  */
  25.  
  26. /*
  27. dcc AddButtons.c -mi -ms -mRR -proto -lbgui
  28. quit
  29. */
  30.  
  31. #include "DemoCode.h"
  32.  
  33. /*
  34.  *      Object ID's. Please note that the ID's are shared
  35.  *      between the menus and the gadget objects.
  36.  */
  37. #define ID_ADD          21
  38. #define ID_QUIT         22
  39. #define ID_INS          23
  40. #define ID_REM          24
  41.  
  42. /*
  43.  *      Simple menu strip.
  44.  */
  45. struct NewMenu SimpleMenu[] = {
  46.    Title( "Project" ),
  47.       Item( "Add",        "A", ID_ADD ),
  48.       Item( "Insert",     "I", ID_INS ),
  49.       Item( "Remove all", "R", ID_REM ),
  50.       ItemBar,
  51.       Item( "Quit",       "Q", ID_QUIT ),
  52.    End
  53. };
  54.  
  55. /*
  56.  *      Simple button creation macros.
  57.  */
  58. #define AddButton\
  59.    ButtonObject,\
  60.       LAB_Label,              "Added",\
  61.       LAB_Style,              FSF_BOLD,\
  62.       FuzzButtonFrame,\
  63.    EndObject
  64.  
  65. #define InsButton\
  66.    ButtonObject,\
  67.       LAB_Label,              "Inserted",\
  68.       LAB_Style,              FSF_BOLD,\
  69.       FuzzButtonFrame,\
  70.    EndObject
  71.  
  72.  
  73. VOID StartDemo( void )
  74. {
  75.    struct Window           *window;
  76.    Object                  *WO_Window, *GO_Add, *GO_Quit, *GO_Ins, *GO_Rem, *addobj[20], *base;
  77.    ULONG                    signal = 0, rc;
  78.    BOOL                     running = TRUE, ok = FALSE;
  79.    int                      x = 0, xx;
  80.  
  81.    /*
  82.     *      Create window object.
  83.     */
  84.    WO_Window = WindowObject,
  85.       WINDOW_Title,           "Add/Insert Demo",
  86.       WINDOW_MenuStrip,       SimpleMenu,
  87.       WINDOW_LockHeight,      TRUE,
  88.       WINDOW_AutoAspect,      TRUE,
  89.       WINDOW_AutoKeyLabel,    TRUE,
  90.       WINDOW_MasterGroup,
  91.          base = HGroupObject,
  92.             StartMember, GO_Add  = FuzzButton( "_Add",        ID_ADD  ), EndMember,
  93.             StartMember, GO_Ins  = FuzzButton( "_Insert",     ID_INS  ), EndMember,
  94.             StartMember, GO_Rem  = FuzzButton( "_Remove all", ID_REM  ), EndMember,
  95.             StartMember, GO_Quit = FuzzButton( "_Quit",       ID_QUIT ), EndMember,
  96.          EndObject,
  97.       EndObject;
  98.  
  99.         /*
  100.          *      OK?
  101.          */
  102.    if ( WO_Window )
  103.    {
  104.       /*
  105.        *      Open window.
  106.        */
  107.       if ( window = WindowOpen( WO_Window ))
  108.       {
  109.          /*
  110.           *      Get signal mask.
  111.           */
  112.          GetAttr( WINDOW_SigMask, WO_Window, &signal );
  113.          do {
  114.             /*
  115.              *      Poll messages.
  116.              */
  117.             Wait( signal );
  118.             while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE )
  119.             {
  120.                switch ( rc )
  121.                {
  122.                case WMHI_CLOSEWINDOW:
  123.                case ID_QUIT:
  124.                   /*
  125.                    *      Bye now.
  126.                    */
  127.                   running = FALSE;
  128.                   break;
  129.  
  130.                case ID_ADD:
  131.                   if ( x == 19 )
  132.                   {
  133.                      Tell( "Max Nr. of gadgets\n" );
  134.                      break;
  135.                   }
  136.                   x++;
  137.  
  138.                   addobj[x]  = AddButton;
  139.  
  140.                   ok = DoMethod( base, GRM_ADDMEMBER, addobj[ x ],
  141.                      LGO_FixMinHeight, FALSE,
  142.                      LGO_Weight,       DEFAULT_WEIGHT,
  143.                      TAG_END );
  144.  
  145.                   if (!ok)
  146.                   {
  147.                      DisposeObject(addobj[ x ]);
  148.                      x--;
  149.                      Tell( "Last object did not fit!\n" );
  150.                   }
  151.  
  152.                   if ( ! window )
  153.                      goto error;
  154.                   break;
  155.  
  156.                case ID_REM:
  157.                   if ( x > 0 )
  158.                   {
  159.                      for ( xx = 1; xx <= x; xx++ )
  160.                      {
  161.                         DoMethod( base, GRM_REMMEMBER, addobj[ xx ] );
  162.                         DisposeObject(addobj[ xx ]);
  163.                      }
  164.                      x = 0;
  165.                   }
  166.                   else
  167.                      Tell("Were out of gadgets!\n");
  168.                   break;
  169.  
  170.                case ID_INS:
  171.                   if ( x == 19 )
  172.                   {
  173.                      Tell( "Max Nr. of gadgets\n" );
  174.                      break;
  175.                   }
  176.                   x++;
  177.  
  178.                   addobj[x]  = InsButton;
  179.  
  180.                   ok = DoMethod( base, GRM_INSERTMEMBER, addobj[ x ], GO_Rem,
  181.                      LGO_FixMinHeight, FALSE,
  182.                      LGO_Weight,       DEFAULT_WEIGHT,
  183.                      TAG_END );
  184.  
  185.                   if (!ok)
  186.                   {
  187.                      DisposeObject(addobj[ x ]);
  188.                      x--;
  189.                      Tell( "Last object did not fit!\n" );
  190.                   }
  191.  
  192.                   if ( ! window )
  193.                      goto error;
  194.                   break;
  195.  
  196.                }
  197.             }
  198.          } while ( running );
  199.       }
  200.       else
  201.          Tell( "Could not open the window\n" );
  202.       error:
  203.       DisposeObject( WO_Window );
  204.    }
  205.    else
  206.       Tell( "Could not create the window object\n" );
  207. }
  208.